@isTest
private class StudentControllerTest {
    
    @isTest
    static void testShouldReturnNewHousehold() {
        newStudentController c = new newStudentController();
        System.assertNotEquals(null, c.getHousehold());
    }

    @isTest
    static void testShouldReturnNewContact() {
        newStudentController c = new newStudentController();
        System.assertNotEquals(null, c.getContact());
    }
    
    @isTest
    static void testShouldReturnNewGuardian() {
        newStudentController c = new newStudentController();
        System.assertNotEquals(null, c.getContact2());
    }

    @isTest
    static void testShouldReturnNewSecondGuardian() {
        newStudentController c = new newStudentController();
        System.assertNotEquals(null, c.getGuardian2());
    }
    
    @isTest
    static void testShouldReturnNewConnector() {
        newStudentController c = new newStudentController();
        System.assertNotEquals(null, c.getConnector());
    }

    @isTest
    static void testShouldReturnNewSecondConnector() {
        newStudentController c = new newStudentController();
        System.assertNotEquals(null, c.getStudentGuardianConnector2());
    }
    
    @isTest
    static void testShouldReturnNewEnrollment() {
        newStudentController c = new newStudentController();
        System.assertNotEquals(null, c.getEnrollment());
    }

    @isTest
    static void testShouldReturnNewMedForm() {
        newStudentController c = new newStudentController();
        System.assertNotEquals(null, c.getMedform());
    }

    @isTest
    static void testShouldReturnStep1() {
        newStudentController c = new newStudentController();
        System.assertNotEquals(Page.StudentDataEntry, c.step1());
    }

    @isTest
    static void testShouldReturnStep2() {
        newStudentController c = new newStudentController();
        System.assertNotEquals(Page.StudentDataEntry2, c.step2());
    }

    @isTest
    static void testShouldReturnStep3() {
        newStudentController c = new newStudentController();
        Contact c1 = c.getContact();
        c1.firstName = 'test';
        c1.lastName = 'test';
        
        Student_Enrollment__c e1 = c.getEnrollment();
        e1.Season__c = 'Fall';
        e1.Year__c = '2009';
        
        Contact c2 = c.getContact2();
        System.assertNotEquals(Page.StudentDataEntry3, c.step3());
    }

    @isTest
    static void testShouldAddSecondGuardian() {
        newStudentController c = new newStudentController();
        c.addGuardian();
        System.assertEquals(true, c.getHasSecondGuardian());
    }
    
    
       @isTest
    static void testShouldRemoveSecondGuardian() {
        newStudentController c = new newStudentController();
        c.removeGuardian();
        System.assertNotEquals(true, c.getHasSecondGuardian());
    }

    @isTest
    static void testgetPDF() {
        newStudentController c = new newStudentController();
        
        System.assertNotEquals(null, c.getPdf());
    }
    
    @isTest
    static void testCancelShouldReturnContactPageRef() {
        newStudentController c = new newStudentController();        
        System.assertNotEquals(null, c.cancel());
    }

    @isTest
    static void testBasicEndToEndScenario() {
        newStudentController sc = new newStudentController();
        //sc.getHousehold();
        Contact c = sc.getContact();
        c.lastName = 'test';
        c.MailingStreet = 'test';       
        c.MailingCity = 'test';
        c.MailingState = 'CA';
        c.MailingPostalCode = '91458';
        c.MailingCountry = 'USA';
        
        Contact g1 = sc.getContact2();
        g1.lastName = 'test';
        g1.email = 'tsest@test.com';
        g1.Phone = '555-5555';
        
        Contact_Connector__c gc1 = sc.getConnector();
        sc.getEnrollment();
        Medical_Form__c mf = sc.getMedform();
        mf.Work_Phone__c = '555-5555';
        mf.emergency_contact__c = '555-5555';
        sc.stepPrint();
        
        //verify that fields are blank
    	System.assertEquals(NULL , sc.getHousehold().MailingStreet__c);
    	System.assertEquals(NULL , sc.getContact().ONEN_Household__c);

       	//perform save
        sc.save();
        
        //check again, there should be a value. 
        ONEN_Household__c hh = [SELECT MailingStreet__c FROM 
        		ONEN_Household__c WHERE id = :sc.getHousehold().ID ];
        System.assertEquals('Test' , hh.MailingStreet__c);
        
        Contact c1 = [SELECT ONEN_Household__c FROM 
        		Contact WHERE id = :sc.getContact().ID ];		

        System.assertEquals(sc.getHousehold().ID , c1.ONEN_Household__c);
        
    }
    
    @isTest
    static void testGetSchools() {
        newStudentController sc = new newStudentController();
        List<SelectOption> listOfSchools = sc.schools;
        sc.getEnrollment();
        System.assertEquals(null, sc.school);
        sc.school = '--None--';
        for(Account school: [select id, name from Account 
                              where recordTypeId=:newStudentController.getLocalSchoolRecordTypeId() 
                              and contract_school__c = true order by name limit 1])
            sc.school = school.id;

    } 
    
    @isTest
    static void testGetGuardianRelationships() {
        newStudentController sc = new newStudentController();
        List<SelectOption> listOfRel =  sc.guardianRelationships;
        sc.getConnector();  
        System.assertEquals(null, sc.primaryGuardianRelationship);
        Schema.DescribeFieldResult f = Contact_Connector__c.Relationship__c.getDescribe();
        for(Schema.PicklistEntry relationship: f.getPicklistValues())
                    if(newStudentController.isValidGuardianRelationship(relationship.getLabel())) {                    
                        sc.primaryGuardianRelationship = relationship.getLabel();
                        break;
                    }
        sc.getStudentGuardianConnector2();  
        System.assertEquals(null, sc.secondaryGuardianRelationship);
        sc.secondaryGuardianRelationship = sc.primaryGuardianRelationship;
    }
    
    @isTest
    static void testGetTeachers() {
        newStudentController sc = new newStudentController();
        List<SelectOption> listOfSchools = sc.teachers;     
        sc.getEnrollment();
        System.assertEquals(null, sc.teacher);
        sc.teacher = listOfSchools.get(0).getValue();
    }
    
        @isTest
    static void testGetStates() {
        newStudentController sc = new newStudentController();
        List<SelectOption> listOfStates = sc.states;     
        sc.getContact();
        System.assertNotEquals(null, sc.states);
    }

    @isTest
    static void testGetGrades() {
        newStudentController sc = new newStudentController();
        List<SelectOption> listOfGrades = sc.grades;        
        sc.getEnrollment();
        //System.assertEquals('--None--', sc.grade);
        sc.teacher = '--None--';
        sc.teacher = listOfGrades.get(0).getValue();
    }
    
    @isTest
    static void testStepPrint() {
        newStudentController sc = new newStudentController();
        sc.getHasPrinted();
        sc.stepPrint();
    }
}